package com.ruiyi.subway.utils;

import org.apache.commons.io.IOUtils;

import javax.servlet.http.HttpServletResponse;
import java.io.InputStream;
import java.io.OutputStream;

public class HttpUtils {

    public static void responseForDownload(InputStream input, String fileName, HttpServletResponse resp) throws Exception {
        OutputStream output = null;
        try {
            resp.setContentType("octet-stream");
            resp.setHeader("Content-Disposition", String.format("attachment;filename=%s", fileName));
            //input = installerService.getInstallerStream(installer);
            output = resp.getOutputStream();
            IOUtils.copy(input, output);
        }finally {
            IOUtils.closeQuietly(input);
            IOUtils.closeQuietly(output);
        }
    }

    public static void responseForPicture(InputStream input, HttpServletResponse resp) throws Exception {
        OutputStream output = null;
        try {
            resp.setContentType("image/jpg");
            output = resp.getOutputStream();
            IOUtils.copy(input, output);
        }finally {
            IOUtils.closeQuietly(input);
            IOUtils.closeQuietly(output);
        }
    }
}
